<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  <head>
    <title>Primitive expression syntax</title>
    <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
    <link rel="stylesheet" type="text/css" href="kawa.css"/>
    <script src="kawa-ebook.js" type="text/javascript"/>
    <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
    <link rel="prev" href="Hash-prefixed-forms.xhtml" title="Hash-prefixed forms"/>
    <link rel="next" href="Colon-notation.xhtml" title="Property access using colon notation"/>
  </head>
  <body>
    <header/>
    <section class="sect1" title="Primitive expression syntax" epub:type="subchapter" id="Primitive-expression-syntax">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both">Primitive expression syntax</h2>
          </div>
        </div>
      </div>
      <div class="literallayout">
        <p><a id="idm139667879292592" class="indexterm"/><span id="meta-expression"/><em class="replaceable"><code>expression</code></em> <code class="literal">::=</code> <a class="link" href="Primitive-expression-syntax.xhtml#meta-literal-expression"><em class="replaceable"><code>literal-expression</code></em></a> | <a class="link" href="Primitive-expression-syntax.xhtml#meta-variable-reference"><em class="replaceable"><code>variable-reference</code></em></a><br/>
  | <a class="link" href="Primitive-expression-syntax.xhtml#meta-procedure-call"><em class="replaceable"><code>procedure-call</code></em></a> | TODO<br/>
</p>
      </div>
      <span id="literal-expression"/>
      <section class="sect2" title="Literal expressions" epub:type="division" id="idm139667879287568">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title">Literal expressions</h3>
            </div>
          </div>
        </div>
        <div class="literallayout">
          <p><a id="idm139667879286496" class="indexterm"/><span id="meta-literal-expression"/><em class="replaceable"><code>literal-expression</code></em> <code class="literal">::=</code> <code class="literal"><span class="bold"><strong>(quote</strong></span></code> <a class="link" href="Datum-syntax.xhtml#meta-datum"><em class="replaceable"><code>datum</code></em></a><code class="literal"><span class="bold"><strong>)</strong></span></code><br/>
  | <code class="literal"><span class="bold"><strong>’</strong></span></code> <a class="link" href="Datum-syntax.xhtml#meta-datum"><em class="replaceable"><code>datum</code></em></a><br/>
  | <em class="replaceable"><code>constant</code></em> <br/>
<a id="idm139667879280112" class="indexterm"/><span id="meta-constant"/><em class="replaceable"><code>constant</code></em> <code class="literal">::=</code> <em class="replaceable"><code>number</code></em> | <em class="replaceable"><code>boolean</code></em> | <em class="replaceable"><code>character</code></em> | <em class="replaceable"><code>string</code></em><br/>
</p>
        </div>
        <p><code class="literal">(quote <em class="replaceable"><code>datum</code></em>)</code> evaluates to <em class="replaceable"><code>datum</code></em>,
which may be any external representation of a Scheme object.
This notation is used to include literal constants in Scheme code.
</p>
        <pre class="screen">(quote a)               ⇒  a 
(quote #(a b c))        ⇒  #(a b c)
(quote (+ 1 2))         ⇒  (+ 1 2)
</pre>
        <p><code class="literal">(quote <em class="replaceable"><code>datum</code></em>)</code> may be abbreviated as <code class="literal">'<em class="replaceable"><code>datum</code></em></code>.
The two notations are equivalent in all respects.
</p>
        <pre class="screen">’a                      ⇒  a
’#(a b c)               ⇒  #(a b c)
’()                     ⇒  ()
’(+ 1 2)                ⇒  (+ 1 2)
’(quote a)              ⇒  (quote a)
’’a                     ⇒  (quote a)
</pre>
        <p>Numerical constants, string constants, character constants,
bytevector constants, and boolean constants evaluate to
themselves; they need not be quoted.
</p>
        <pre class="screen">145932          ⇒  145932
#t              ⇒  #t
"abc"           ⇒  "abc"
</pre>
        <p>Note that <a class="link" href="Keywords.xhtml" title="Keywords">keywords</a> need to be quoted,
unlike some other Lisp/Scheme dialect, including Common Lisp,
and earlier versions of Kawa.  (Kawa currently evaluates a non-quoted
keyword as itself, but that will change.)
</p>
        <span id="variable-reference"/>
      </section>
      <section class="sect2" title="Variable references" epub:type="division" id="idm139667879268592">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title">Variable references</h3>
            </div>
          </div>
        </div>
        <div class="literallayout">
          <p><a id="idm139667879267520" class="indexterm"/><span id="meta-variable-reference"/><em class="replaceable"><code>variable-reference</code></em> <code class="literal">::=</code> <a class="link" href="Lexical-syntax.xhtml#meta-identifier"><em class="replaceable"><code>identifier</code></em></a><br/>
</p>
        </div>
        <p>An expression consisting of a variable is a variable reference if it is
not a macro use (see below).  The value of the variable reference is the
value stored in the location to which the variable is bound.  It is a
syntax violation to reference an unbound variable.
</p>
        <p>The following example assumes the base library has been
imported:
</p>
        <pre class="screen">(define x 28)
x   ⇒  28
</pre>
      </section>
      <section class="sect2" title="Procedure calls" epub:type="division" id="idm139667879263008">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title">Procedure calls</h3>
            </div>
          </div>
        </div>
        <div class="literallayout">
          <p><a id="idm139667879261936" class="indexterm"/><span id="meta-procedure-call"/><em class="replaceable"><code>procedure-call</code></em> <code class="literal">::=</code> <code class="literal"><span class="bold"><strong>(</strong></span></code><a class="link" href="Primitive-expression-syntax.xhtml#meta-operator"><em class="replaceable"><code>operator</code></em></a> <a class="link" href="Primitive-expression-syntax.xhtml#meta-operand"><em class="replaceable"><code>operand</code></em></a> …)<br/>
<a id="idm139667879257632" class="indexterm"/><span id="meta-operator"/><em class="replaceable"><code>operator</code></em> <code class="literal">::=</code> <a class="link" href="Primitive-expression-syntax.xhtml#meta-expression"><em class="replaceable"><code>expression</code></em></a><br/>
<a id="idm139667879254832" class="indexterm"/><span id="meta-operand"/><em class="replaceable"><code>operand</code></em> <code class="literal">::=</code> <a class="link" href="Primitive-expression-syntax.xhtml#meta-expression"><em class="replaceable"><code>expression</code></em></a><br/>
  | <a class="link" href="Keywords.xhtml#meta-keyword"><em class="replaceable"><code>keyword</code></em></a> <a class="link" href="Primitive-expression-syntax.xhtml#meta-expression"><em class="replaceable"><code>expression</code></em></a><br/>
  | <code class="literal">@</code> <a class="link" href="Primitive-expression-syntax.xhtml#meta-expression"><em class="replaceable"><code>expression</code></em></a><br/>
  | <code class="literal">@:</code> <a class="link" href="Primitive-expression-syntax.xhtml#meta-expression"><em class="replaceable"><code>expression</code></em></a><br/>
</p>
        </div>
        <p>A procedure call consists of expressions for the procedure to be called
and the arguments to be passed to it, with enclosing parentheses.  A
form in an expression context is a procedure call if <em class="replaceable"><code>operator</code></em> is
not an identifier bound as a syntactic keyword.
</p>
        <p>When a procedure call is evaluated, the operator and operand expressions
are evaluated (in an unspecified order) and the resulting procedure is
passed the resulting arguments.
</p>
        <pre class="screen">(+ 3 4)                ⇒  7
((if #f + *) 3 4)      ⇒  12
</pre>
        <p>The syntax <a class="link" href="Keywords.xhtml#meta-keyword"><em class="replaceable"><code>keyword</code></em></a> <em class="replaceable"><code>expression</code></em> is a <em class="firstterm">keyword argument</em>.
This is a mechanism for specifying arguments using a name rather than position,
and is especially useful for procedures with many optional paramaters.
Note that <a class="link" href="Keywords.xhtml#meta-keyword"><em class="replaceable"><code>keyword</code></em></a> must be literal, and cannot be the
result from evaluating a non-literal expression.
(This is a change from previous versions of Kawa,
and is different from Common Lisp and some other Scheme dialects.)
</p>
        <p>An expression prefixed by <code class="literal">@</code> or <code class="literal">@:</code> is
a splice argument.  The following expression must evaluate to an
“argument list” (see <a class="link" href="Application-and-Arguments-Lists.xhtml" title="Application and Arguments Lists">Application and Arguments Lists</a> for details);
each element in the argument
becomes a separate argument when call the <em class="replaceable"><code>operator</code></em>.
(This is very similar to the “spread” operator is EcmaScript 6.)
</p>
      </section>
    </section>
    <footer>
      <div class="navfooter">
        <ul>
          <li>
            <b class="toc">
              <a href="Primitive-expression-syntax.xhtml#idm139667879287568">Literal expressions</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="Primitive-expression-syntax.xhtml#idm139667879268592">Variable references</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="Primitive-expression-syntax.xhtml#idm139667879263008">Procedure calls</a>
            </b>
          </li>
        </ul>
        <p>
          Up: <a accesskey="u" href="Syntax.xhtml">Syntax</a></p>
        <p>
        Previous: <a accesskey="p" href="Hash-prefixed-forms.xhtml">Hash-prefixed forms</a></p>
        <p>
        Next: <a accesskey="n" href="Colon-notation.xhtml">Property access using colon notation</a></p>
      </div>
    </footer>
  </body>
</html>
